package com.bwie.controller;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.utils.Result;
import com.bwie.vo.LoginForm;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.PageVo;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @description :
 * @Author QiHainan
 * @Create 2025/5/21 16:32
 * @Version 1.0
 */
@RestController
@RequestMapping("/auth/index")
public class IndexController {
    @Autowired
    TbUserService tbUserService;
    @Autowired
    StringRedisTemplate redisTemplate;

    /**
     * 登录
     * @param loginForm
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody @Validated LoginForm loginForm, BindingResult result){
        if(result.hasErrors()){
            return Result.error().setMsg(result.getFieldError().getDefaultMessage());
        }
        return tbUserService.login(loginForm);
    }

    /**
     * 获取用户权限菜单
     * @return
     */
    @PostMapping("/getMenuList")
    public Result getMenuList(){
        return tbUserService.getMenuList();
    }

    /**
     * 获取商户条件分页列表
     * @param pageVo
     * @return
     */
    @PostMapping("/getUserPage")
    public Result getUserPage(@RequestBody PageVo pageVo){
        return tbUserService.getUserPage(pageVo);
    }

    /**
     * 上传文件
     * @param file
     * @return
     */
    @PostMapping("/uploadImage")
    public Result uploadImage(@RequestPart("file")MultipartFile file){
        return tbUserService.uploadImage(file);
    }

    /**
     * 修改商户信息
     * @param tbUser
     * @return
     */
    @PostMapping("/updateUser")
    public Result updateUser(@RequestBody TbUser tbUser){
        return tbUserService.updateUser(tbUser);
    }

    /**
     * 根据iD删除单个商户
     * @param id
     * @return
     */
    @PostMapping("/deleteByUserId/{id}")
    public Result deleteByUserId(@PathVariable("id") Integer id){
        return tbUserService.deleteByUserId(id);
    }

    /**
     * 批量删除商户
     * @param ids
     * @return
     */
    @PostMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<TbUser> ids){
        return tbUserService.deleteBatch(ids);
    }

    /**
     * 审核商户
     * @param tbUser
     * @return
     */
    @PostMapping("/checkUser")
    public Result checkUser(@RequestBody TbUser tbUser){
        return tbUserService.checkUser(tbUser);
    }
}
